package com.dwxt.common.wxpay;

import lombok.extern.slf4j.Slf4j;

import java.io.*;

@Slf4j
public class MinWXPayConfig extends WXPayConfig {
    private byte[] certData;


    @Override
    public String getAppID() {
        //return "wx7d683cbdfd852d57";
        return "wx44613790d6c45749";
    }

    @Override
    public String getMchID() {
        return "1591403211";
    }

    @Override
    public String getKey() {
        return "0iciWy4kczxK6e1ffkYesvpqh8gkvnhF";
    }

    public MinWXPayConfig() { // 构造方法读取证书, 通过getCertStream 可以使sdk获取到证书
        //String certPath = "C:\\Users\\Administrator\\Desktop\\cert\\apiclient_cert.p12";
        //String certPath = "/opt/P12/apiclient_cert.p12";
        //String activeProfile = SpringContextUtil.getActiveProfile();
        //String certPath = PropertiesFileUtil.getInstance("/application-" + activeProfile).get("path");
        //this.payAccount = payAccount;
        try {
            File file = new File("/app/city/certificate/apiclient_cert.p12");
            InputStream certStream = new FileInputStream(file);
            this.certData = new byte[(int) file.length()];
            certStream.read(this.certData);
            certStream.close();
        } catch (IOException e) {
            log.error(e.toString());
        }
    }

    @Override
    InputStream getCertStream() {
        return new ByteArrayInputStream(this.certData);
    }

    @Override
    IWXPayDomain getWXPayDomain() {
        IWXPayDomain iwxPayDomain = new IWXPayDomain() {
            @Override
            public void report(String domain, long elapsedTimeMillis, Exception ex) {

            }

            @Override
            public DomainInfo getDomain(WXPayConfig config) {
                return new DomainInfo(WXPayConstants.DOMAIN_API, true);
            }
        };
        return iwxPayDomain;
    }
}
